import pandas as pd
from sklearn.preprocessing import LabelEncoder
import seaborn as sns
import matplotlib.pyplot as plt

plt.rcParams['font.family'] = 'Times New Roman'


class Utils:
    @staticmethod
    def process_missing_values(csv_name='Houston.csv'):
        df = pd.read_csv(csv_name)

        df = df.drop(0)

        print('Missing Values Before Processing:', df.isnull().sum().sum())

        df = df.interpolate()

        print('Missing Values After Processing:', df.isnull().sum().sum())

        return df

    @staticmethod
    def process_label_encoder(df):
        label_encoder = LabelEncoder()
        df['weather'] = label_encoder.fit_transform(df['weather'])
        category_mapping = dict(zip(label_encoder.classes_, label_encoder.transform(label_encoder.classes_)))
        print(category_mapping)
        return df

    @staticmethod
    def correlation_analysis(df):
        # Calculate correlation matrix
        correlation_matrix = df.corr()

        # Display correlation matrix
        print('Correlation Matrix:')
        print(correlation_matrix)
        plt.figure(figsize=(10, 8))
        sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt=".2f")
        plt.title('Correlation Heatmap')
        plt.show()


if __name__ == "__main__":
    utils = Utils()
    df_processed = utils.process_missing_values()
    df_encoded = utils.process_label_encoder(df_processed)
    utils.correlation_analysis(df_encoded)
